package com.asl.website.serviceDetails.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.asl.website.serviceDetails.domain.TransportServiceDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.asl.common.annotation.Log;
import com.asl.common.core.controller.BaseController;
import com.asl.common.core.domain.AjaxResult;
import com.asl.common.enums.BusinessType;
import com.asl.website.serviceDetails.domain.TTransportService;
import com.asl.website.serviceDetails.service.ITTransportServiceService;
import com.asl.common.utils.poi.ExcelUtil;
import com.asl.common.core.page.TableDataInfo;

/**
 * 运输服务详情Controller
 * 
 * @author ruoyi
 * @date 2025-05-21
 */
@RestController
@RequestMapping("/serviceDetails/serviceDetails")
public class TTransportServiceController extends BaseController
{
    @Autowired
    private ITTransportServiceService tTransportServiceService;

    /**
     * 获取单个服务详情
     * @param id 服务ID
     * @param acceptLanguage 语言标识
     * @return 服务详情
     */
    @GetMapping("/detail/{id}")
    public AjaxResult getTransportServiceDetail(
            @PathVariable Long id,
            @RequestHeader(value = "Accept-Language", defaultValue = "zh-CN") String acceptLanguage) {

        TTransportService service = tTransportServiceService.selectTTransportServiceById(id);
        if (service == null) {
            return AjaxResult.error("运输服务不存在");
        }

        return AjaxResult.success(new TransportServiceDTO(service, acceptLanguage));
    }

    /**
     * 查询运输服务详情列表
     */
    @PreAuthorize("@ss.hasPermi('serviceDetails:serviceDetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(TTransportService tTransportService)
    {
        startPage();
        List<TTransportService> list = tTransportServiceService.selectTTransportServiceList(tTransportService);
        return getDataTable(list);
    }

    /**
     * 导出运输服务详情列表
     */
    @PreAuthorize("@ss.hasPermi('serviceDetails:serviceDetails:export')")
    @Log(title = "运输服务详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTransportService tTransportService)
    {
        List<TTransportService> list = tTransportServiceService.selectTTransportServiceList(tTransportService);
        ExcelUtil<TTransportService> util = new ExcelUtil<TTransportService>(TTransportService.class);
        util.exportExcel(response, list, "运输服务详情数据");
    }

    /**
     * 获取运输服务详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('serviceDetails:serviceDetails:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tTransportServiceService.selectTTransportServiceById(id));
    }

    /**
     * 新增运输服务详情
     */
    @PreAuthorize("@ss.hasPermi('serviceDetails:serviceDetails:add')")
    @Log(title = "运输服务详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTransportService tTransportService)
    {
        return toAjax(tTransportServiceService.insertTTransportService(tTransportService));
    }

    /**
     * 修改运输服务详情
     */
    @PreAuthorize("@ss.hasPermi('serviceDetails:serviceDetails:edit')")
    @Log(title = "运输服务详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTransportService tTransportService)
    {
        return toAjax(tTransportServiceService.updateTTransportService(tTransportService));
    }

    /**
     * 删除运输服务详情
     */
    @PreAuthorize("@ss.hasPermi('serviceDetails:serviceDetails:remove')")
    @Log(title = "运输服务详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tTransportServiceService.deleteTTransportServiceByIds(ids));
    }
}
